<%--
  Created by IntelliJ IDEA.
  User: zhangjie
  Date: 2018/9/7
  Time: 9:37 AM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<html>
<head>
    <title>骨松筛查</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/paginate.css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/qulitity.css" type="text/css" type="text/css">
    <%--<link rel="stylesheet" href="../assets/css/views/modules/_common.scss">--%>
    <link rel="stylesheet" href="${assets}/css/views/department/departmentMgr.css">
    <link rel="stylesheet" href="${assets}/css/views/bloodScreening.css">
    <script src="../assets/js/views/vue.min.js"></script>
    <script type="text/javascript" src="${assets}/js/echarts.js"></script>
    <script src="${js}/jquery-1.9.1.min.js"></script>
    <script src="${js}/jquery.dataTables.js"></script>
    <script src="${frames}/Chronic/laydate/laydate.js"></script>
    <style>
        .color{
            margin:0 !important;
        }
        .btn{
            float:right ;
            width:100px;
            font-size:16px;
            line-height:28px;
            background:#35acfd !important;
            margin-right:15px !important;
            padding:0 !important;
        }
        .defalts{
            border:1px solid red !important;
        }
    </style>
</head>
<body>
<div>
    <%@ include file="../../breadline.jsp" %>
</div>
<div id="main">
    <div style="width:100%;">
        <div>
            <%@ include file="../../personalnews.jsp" %>
        </div>
        <div class="illness">
            <div style="margin-left:20px;padding-top:20px;padding-bottom:40px;">
                <h3 style="margin-bottom:16px;">糖尿病疾病筛查</h3>
                <div class="bpinfo" >
                    <div class="test" >
                        <div>
                            <span style="width:5px;padding-bottom:25px;background-color:#35acfd;display:inline-block;vertical-align:middle"></span>
                            <span class="topic">服务对象</span>
                            <button type="button" class="btn btn-info" @click="getVal()">
                                <img src="../assets/images/revise.png" alt="" style="width:16px;vertical-align: middle;">  保存
                            </button>
                        </div>
                        <div class="feritin">
                            <div id="isPatient">
                                <span class="title">辖区内35岁及以上常住居民中2型糖尿病患者</span>
                                <span class="types">
                                    <input type="radio" value="1" name="class" id="r1">
                                    <label for="r1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="class" id="r2">
                                    <label for="r2">否</label>
                                </span>
                            </div>
                        </div>
                        <div>
                            <span style="width:5px;padding-bottom:25px;background-color:#35acfd;display:inline-block;vertical-align:middle"></span>
                            <span class="topic">服务内容评估</span>
                        </div>
                        <div class="evaluate">
                            <div>
                                <label class="title">血糖类型:</label>
                                <select name="bloodSugarType" id="bloodSugarType" class="SN">
                                    <medi:configOpt name="bloodSugarType"/>
                                </select>
                                <label class="title">血糖值:</label>
                                <div class="inputWrap">
                                    <input type="text" class="SN" id="bloodSugarValue" name="bloodSugarValue">
                                    <span>mmol/L</span>
                                </div>

                                <label class="title">评估日期:</label>
                                <input id="evaluateDate" type="text" class="lay-date" placeholder="选择时间" readonly>
                                <br>
                                <label class="title">管理方式:</label>
                                <select name="managementType" id="managementType" class="SN">
                                    <medi:configOpt name="managementType"/>
                                </select>
                            </div>
                        </div>
                        <div>
                            <span style="width:5px;padding-bottom:25px;background-color:#35acfd;display:inline-block;vertical-align:middle"></span>
                            <span class="topic">服务内容筛选</span>
                        </div>
                        <div class="serviceContent">
                            <div id="measure">
                                <span class="title">
                                    （1）测量空腹血糖和血压，并评估是否存在危急情况，如出现血糖≥16.7mmol/L或血糖≤3.9mmol/L;收缩压≥180mmHg和/或舒张压≥110mmHg
                                </span>
                                <span class="types">
                                    <input type="radio" value="1" name="measure" id="s1">
                                    <label for="s1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="measure" id="s2">
                                    <label for="s2">否</label>
                                </span>
                            </div>
                            <div id="Symptom">
                                <span class="title">（2）意识或行为改变、呼气烂苹果样丙酮味、心悸、出汗、食欲减退、恶心、呕吐、多饮、多尿、腹痛、有深大呼吸、皮肤潮红</span>
                                <span class="types">
                                    <input type="radio" value="1" name="Symptom" id="t1">
                                    <label for="t1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="Symptom" id="t2">
                                    <label for="t2">否</label>
                                </span>
                            </div>
                            <div id="tachycardia">
                                <span class="title">（3）持续性心动过速（心率超过100次/分钟）</span>
                                <span class="types">
                                    <input type="radio" value="1" name="tachycardia" id="p1">
                                    <label for="p1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="tachycardia" id="p2">
                                    <label for="p2">否</label>
                                </span>
                            </div>
                            <div id="sudden">
                                <span class="title">（4）体温超过39摄氏度或有其他的突发异常情况，如视力突然骤降、妊娠期及哺乳期血糖高于正常值</span>
                                <span class="types">
                                    <input type="radio" value="1" name="sudden" id="q1">
                                    <label for="q1">是</label>
                                </span>
                                <span class="types">
                                    <input type="radio" value="0" name="sudden" id="q2">
                                    <label for="q2">否</label>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="tip display1">
                    <span><img src="../assets/images/iconTip.png" alt=""></span>
                    <span>您已占四项高危因素，建议每半年至少测量1次血糖，并接受医务人员的生活方式指导！</span>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    var vm = new Vue({
        el : "#main",
        data: {
            infor: [],//病人基本信息data
            id:'',
            idCard:'',
            ispatient:'',
            measure:'',
            Symptom:'',
            tachycardia:'',
            sudden:'',
            synchronous:false,
            btnText:'',
            dis:false
        },
        methods:{
            //修改病人基本信息
            addDevice:function(){
                let that= this;
                window.parent.showNewModelIframe("${URL_PATIENT_PATIENT}?id="+that.infor.id+'&diseasesType='+that.diseasesType,800,650);
            },
            //保存血压筛查信息
            getVal:function(){
                let _this=this;
                var INPUT=$('.bpinfo  input[value="1"]:checked');
                var INPUT1=$("#isPatient input");
                var INPUT2=$("#measure input");
                var INPUT3=$("#Symptom input");
                var INPUT4=$("#tachycardia input");
                var INPUT5=$("#sudden input");
                for(var i=0;i<INPUT1.length;i++){
                    if(INPUT1[i].checked==0){
                        _this.ispatient=1;
                    }else{
                        _this.ispatient=0;
                    }
                }
                for(var i=0;i<INPUT2.length;i++){
                    if(INPUT2[i].checked==0){
                        _this.measure=1;
                    }else{
                        _this.measure=0;
                    }
                }
                for(var i=0;i<INPUT3.length;i++){
                    if(INPUT3[i].checked==0){
                        _this.Symptom=1;
                    }else{
                        _this.Symptom=0;
                    }
                }
                for(var i=0;i<INPUT4.length;i++){
                    if(INPUT4[i].checked==0){
                        _this.tachycardia=1;
                    }else{
                        _this.tachycardia=0;
                    }
                }
                for(var i=0;i<INPUT5.length;i++){
                    if(INPUT5[i].checked==0){
                        _this.sudden=1;
                    }else{
                        _this.sudden=0;
                    }
                }
                if(INPUT.length>=4){
                    $(".tip").removeClass('display1');
                }else{
                    $(".tip").addClass('display1');
                }
                var app = []
                if("${id}"==''){
                    if( $("#isPatient input[type='radio']:checked").length != 1 || $('#bloodSugarType option:selected').val() === '' || $('#managementType option:selected').val() === ''
                    || $('#bloodSugarValue').val() === "" || $('#evaluateDate').val() === "" ){
                        if( $("#isPatient input[type='radio']:checked").length != 1 ){
                            if( $('#isPatient').children(":last").hasClass('defalt') ){

                            }else{
                                $('#isPatient').children(":last").after('<span class="defalt" style="margin-left:10px;color:red;font-size:15px;">'+'该选项未选择'+'</span>')
                                app.push($('#isPatient'))
                            }
                            app.push($("#isPatient"))
                        }else{
                            if( $('#isPatient .defalt') ){
                                $('#isPatient .defalt').remove()
                            }
                        }
                        if(app[0]){
                            var offset = $(app[0]).offset().top
                            parent.$("html,body").animate({ scrollTop: offset}, 0);
                        }
                        if( $('#bloodSugarValue').val() === "" ){
                            $('#bloodSugarValue').attr('placeholder','请输入数值')
                            $('#bloodSugarValue').parent('.inputWrap').addClass('defalts')
                        }else{
                            if( $('#bloodSugarValue').parent('.inputWrap').hasClass('defalts') ){
                                $('#bloodSugarValue').parent('.inputWrap').removeClass('defalts')
                            }
                        }
                        if( $('#evaluateDate').val() === "" ){
                            $('#evaluateDate').attr('placeholder','请输入数值')
                            $('#evaluateDate').addClass('defalts')
                        }else{
                            if( $('#evaluateDate').hasClass('defalts') ){
                                $('#evaluateDate').removeClass('defalts')
                            }
                        }
                        if( $('#bloodSugarType option:selected').val() === '' ){
                            $('#bloodSugarType').addClass('defalts')
                        }else{
                            console.log(111)
                            if( $('#bloodSugarType').hasClass('defalts')){

                                $('#bloodSugarType').removeClass('defalts')
                            }
                        }
                        if( $('#managementType option:selected').val() === '' ){
                            $('#managementType').addClass('defalts')
                        }else{
                            if( $('#managementType').hasClass('defalts') ){
                                $('#managementType').removeClass('defalts')
                            }
                        }
                    }else{
                        $.ajax({
                            url:"${URL_SCREENING_SAVEBS}",
                            type:'post',
                            dataType: "json",
                            data:{
                                idCard:'${idcard}',
                                patient:_this.ispatient,
                                danger:_this.measure,
                                Symptom:_this.Symptom,
                                heartbeat:_this.tachycardia,
                                temperature:_this.sudden,
                                bloodSugarType:$('#bloodSugarType option:selected').val(),
                                bloodSugarValue:$('#bloodSugarValue').val(),
                                screeningTime:$("#evaluateDate").val(),
                                managementType:$('#managementType option:selected').val()
                            },
                            success: function(data) {
                                console.log(data);
                                if(data.success){
                                    parent.showSrc('${URL_SCREENING_BSSCREENINGS}?idcard=' + '${idcard}')
                                }else{
                                    alert("保存失败！");
                                }
                            }
                        })
                    }
                }else{
                    if( $("#isPatient input[type='radio']:checked").length != 1 || $('#bloodSugarType options:selected').val() === '' || $('#managementType options:selected').val() === ''
                        || $('#bloodSugarValue').val() === "" || $('#evaluateDate').val() === "" ){
                        if( $("#isPatient input[type='radio']:checked").length != 1 ){
                            if( $('#isPatient').children(":last").hasClass('defalt') ){

                            }else{
                                $('#isPatient').children(":last").after('<span class="defalt" style="margin-left:10px;color:red;font-size:15px;">'+'该选项未选择'+'</span>')
                                app.push($('#isPatient'))
                            }
                            app.push($("#isPatient"))
                        }else{
                            if( $('#isPatient .defalt') ){
                                $('#isPatient .defalt').remove()
                            }
                        }
                        if(app[0]){
                            var offset = $(app[0]).offset().top
                            parent.$("html,body").animate({ scrollTop: offset}, 0);
                        }
                        if( $('#bloodSugarValue').val() === "" ){
                            $('#bloodSugarValue').attr('placeholder','请输入数值')
                            $('#bloodSugarValue').parent('.inputWrap').addClass('defalts')
                        }else{
                            if( $('#bloodSugarValue').parent('.inputWrap').hasClass('defalts') ){
                                $('#bloodSugarValue').parent('.inputWrap').removeClass('defalts')
                            }
                        }
                        if( $('#evaluateDate').val() === "" ){
                            $('#evaluateDate').attr('placeholder','请输入数值')
                            $('#evaluateDate').addClass('defalts')
                        }else{
                            if( $('#evaluateDate').hasClass('defalts') ){
                                $('#evaluateDate').removeClass('defalts')
                            }
                        }
                        console.log($('#bloodSugarType option:selected').val())
                        console.log($('#managementType option:selected').val())
                        if( $('#bloodSugarType option:selected').val() === '' ){
                            $('#bloodSugarType').addClass('defalts')
                        }else{
                            console.log(111)
                            if( $('#bloodSugarType').hasClass('defalts')){

                                $('#bloodSugarType').removeClass('defalts')
                            }
                        }
                        if( $('#managementType option:selected').val() === '' ){
                            $('#managementType').addClass('defalts')
                        }else{
                            if( $('#managementType').hasClass('defalts') ){
                                $('#managementType').removeClass('defalts')
                            }
                        }
                    }else{
                        $.ajax({
                            url:"${URL_SCREENING_SAVEBS}",
                            type:'post',
                            dataType: "json",
                            data:{
                                id:'${id}',
                                idCard:'${idcard}',
                                patient:_this.ispatient,
                                danger:_this.measure,
                                Symptom:_this.Symptom,
                                heartbeat:_this.tachycardia,
                                temperature:_this.sudden,
                                bloodSugarType:$('#bloodSugarType option:selected').val(),
                                bloodSugarValue:$('#bloodSugarValue').val(),
                                screeningTime:$("#evaluateDate").val(),
                                managementType:$('#managementType option:selected').val()
                            },
                            success: function(data) {
                                console.log(data);
                                if(data.success){
                                    parent.showSrc('${URL_SCREENING_BSSCREENINGS}?idcard=' + '${idcard}')
                                }else{

                                }
                            }
                        })
                    }
                }
            },
            Synchronous(e){
                let that = this
                $.ajax({
                    url:'${URL_PATIENT_UPDATEPATIENT}',
                    data:{
                        id:that.infor.id,
                        synchronization:'1'
                    },
                    type:'post',
                    dataType:'json',
                    success:function(data){
                        console.log(data)
                        if(data.success){
                            e.target.disabled = true;
                            e.target.innerText = '正在同步'
                            that.setTime()
                        }else{
                            window.parent.showNewModelIframe('${URL_COMMON_TOTIPS}?title='+data.msg,300,200)
                        }
                    }
                })
            },
            setTime(){
                let that = this
                setInterval(function(){
                    $.ajax({
                        url:'${URL_PATIENT_UPDATEPATIENT}',
                        data:{
                            id:that.infor.id,
                            synchronization:'1'
                        },
                        type:'post',
                        dataType:'json',
                        success:function(data){

                        }
                    })
                },10000)
            }
        },
        mounted() {
            let that = this;
            // 获取病人基本信息
            $.ajax({
                url:"${URL_PATIENT_PATIENTINFO}",
                type:'post',
                dataType: "json",
                data:{
                    idCard:"${idcard}"
                },
                success: function(data) {
                    that.infor = data.data;
                    var href = that.infor.diseasesType
//                    that.infor.diseasesType = Type(that.infor.diseasesType)
                    that.id=that.infor.id;
                    that.idCard='${idcard}';
                }
            })
        }
    })
    $(document).ready(function() {
        initLayDate('#evaluateDate');
        $(".bpinfo  input").each(function(index){
            $(this).click(function(){
                var checkedNum=$('.bpinfo  input[value="1"]:checked').length;
                if(checkedNum>=4){
                    $('.tip').removeClass('display1');
                }else{
                    $('.tip').addClass('display1');
                }
            });
        });
        if("${id}"!=''){
            //获取糖尿病疾病筛查信息
            $.ajax({
                url: "${URL_SCREENING_BSDATA}",
                type:'post',
                dataType: "json",
                data:{
                    id:'${id}'
                },
                success: function(data) {
                    console.log(data)
                    if(data.data.patient){
                        $("#r1").attr("checked","checked");
                    }else{
                        $("#r2").attr("checked","checked");
                    }
                    if(data.data.danger){
                        $("#s1").attr("checked","checked");
                    }else{
                        $("#s2").attr("checked","checked");
                    }
                    if(data.data.symptom){
                        $("#t1").attr("checked","checked");
                    }else{
                        $("#t2").attr("checked","checked");
                    }
                    if(data.data.heartbeat){
                        $("#p1").attr("checked","checked");
                    }else{
                        $("#p2").attr("checked","checked");
                    }
                    if(data.data.temperature){
                        $("#q1").attr("checked","checked");
                    }else{
                        $("#q2").attr("checked","checked");
                    }
                    if(data.data.bloodSugarType=='1'){
                        $('#bloodSugarType option:selected').text('空腹血糖');
                        $('#bloodSugarType option:selected').val('1');
                    }else{
                        $('#bloodSugarType option:selected').text('餐后2小时');
                        $('#bloodSugarType option:selected').val('2');
                    }
                    $('#bloodSugarValue').val(data.data.bloodSugarValue);
                    $("#evaluateDate").val(data.data.screeningTime);
                    if(data.data.managementType=='1'){
                        $('#managementType option:selected').text('一般管理');
                        $('#managementType option:selected').val('1');
                    }else{
                        $('#managementType option:selected').text('强化管理');
                        $('#managementType option:selected').val('2');
                    }
                    if($('.bpinfo  input[value="1"]:checked').length>=4){
                        $('.tip').removeClass('display1');
                    }
                    $(".bpinfo  input").each(function(index){
                        $(this).click(function(){
                            var checkedNum=$('.bpinfo  input[value="1"]:checked').length;
                            if(checkedNum>=4){
                                $('.tip').removeClass('display1');
                            }else{
                                $('.tip').addClass('display1');
                            }
                        });
                    });
                }
            })
        }else{
            $.ajax({
                url:"${URL_PPPATIENTBASE_PATIENTDATA}",
                type:'get',
                dataType: "json",
                data:{
                    idCard:"${idcard}"
                },
                success: function(data) {
                    if( data.data != null ){
                        console.log(data.data)
                        $('#bloodSugarValue').val(data.data.bloodSugar)
                    }
                }
            })
        }
    })
    function initLayDate(id) {
        laydate({
            elem: id,
            istime: true,
            format: 'YYYY-MM-DD',
            choose: function (dates) { //选择好日期的回调
                // initTablePatient();
            }
        })
    }
</script>
</body>
</html>
